package com.koron.order.zsjRepair.controller;


import com.koron.bean.base.Response;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.defect.bean.vo.DefectVO;
import com.koron.order.zsjRepair.bean.RemoteRecord;
import com.koron.order.zsjRepair.service.ZsjRepairService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/ZsjController")
@RestController
@Api(tags = "珠三角缺陷工单")
public class ZsjRepairController {

	private String getCurrDs() {
		return ThreadLocalContext.get().getCurrDs();
	}

	@Autowired
	private ZsjRepairService zsjRepairService;

	@ApiOperation(value = "查询用户待办的所有工单")
	@GetMapping("queryListByWorkerId")
	public Response<Object> queryListByWorkerId(String worker) {
		List<DefectVO> orders = ADOConnection.runTask(getCurrDs(), zsjRepairService, "queryListByWorkerId", List.class, worker);
		return Response.success("执行成功",orders.size() == 0 ? "没有待执行工单" : orders , orders.size());
	}

	@ApiOperation(value = "根据名称查询用户待办的工单")
	@GetMapping("queryRepairByName")
	public Response<Object> queryRepairByName(@RequestParam("worker") String worker, @RequestParam("title") String title) {
		if(StringUtils.isBlank(worker))
			worker = ThreadLocalContext.get().getAccount();
		List<DefectVO> orders = ADOConnection.runTask(getCurrDs(), zsjRepairService, "queryRepairByName", List.class, worker, title);
		return Response.success("执行成功",orders.size() == 0 ? "没有待执行工单" : orders , orders.size());
	}

	@ApiOperation(value = "根据工单id查询工单相关的设备id")
	@GetMapping("getDeviceTypeByOrderId")
	public String getDeviceTypeByOrderId(String id){
		return ADOConnection.runTask(getCurrDs(),zsjRepairService,"getDeviceTypeByOrderId",String.class,id);
	}

	@ApiOperation(value = "保存眼镜端的执行信息")
	@PostMapping("saveOrderInfoWithRemote")
	public Response saveOrderInfoWithRemote(@RequestBody RemoteRecord record){
		return ADOConnection.runTask(getCurrDs(),zsjRepairService,"saveOrderInfoWithRemote",Response.class,record);
	}

	@ApiOperation(value = "获取眼镜端的执行信息")
	@GetMapping("getOrderInfoWithRemote")
	public Response getOrderInfoWithRemote(String orderId){
		return Response.success(ADOConnection.runTask(getCurrDs(),zsjRepairService,"getOrderInfoWithRemote", List.class,orderId));
	}

	@ApiOperation(value = "删除眼镜端的执行信息中的附件")
	@GetMapping("deleteStepFileWithRemote")
	public Response deleteStepFileWithRemote(String fileId){
		return Response.success(ADOConnection.runTask(getCurrDs(),zsjRepairService,"deleteStepFileWithRemote", Integer.class,fileId));
	}
}
